package com.cmpp.client.util;

import java.util.Properties;
import java.io.InputStream;
import java.io.FileInputStream;

public class CMPPConfig {
    
    
    // 网关IP
    public static String ServerIp;
    // 网关端口
    public static int ServerPort;
    // 服务代码
    public static String ServiceCode;
    // 企业代码
    public static String CompanyCode;
    // 业务代码
    public static String BusinessCode;
    // 密码
    public static String Pwd;
    //超时时间
    public static String TimeOut;
    //尝试连接次数
    public static String ConnectCount;
    
    public void loadInitCfg(){
        
        try{

          InputStream is = new FileInputStream("Cmpp.cfg") ;
          Properties pt = new Properties() ;
          pt.load(is) ;

          /** 更改SOCKET通讯配置参数 **/
          CMPPConfig.ServerIp = pt.getProperty("ServerIP", "127.0.0.1");
          System.out.println("网关服务器IP: \t" + CMPPConfig.ServerIp);

          CMPPConfig.ServerPort = Integer.parseInt(pt.getProperty("ServerPort", "1020"));
          System.out.println("网关服务器端口: \t" + CMPPConfig.ServerPort);

          CMPPConfig.CompanyCode = pt.getProperty("CompanyCode", "901234");
          System.out.println("企业代码: \t" + CMPPConfig.CompanyCode);

          CMPPConfig.Pwd = pt.getProperty("Pwd", "1234");
          System.out.println("登录密码: \t" + CMPPConfig.Pwd);
          
          CMPPConfig.TimeOut = pt.getProperty("TimeOut", "60");
          System.out.println("超时时间: \t" + CMPPConfig.TimeOut);
          
          CMPPConfig.ConnectCount = pt.getProperty("ConnectCount", "3");
          System.out.println("尝试连接次数: \t" + CMPPConfig.ConnectCount);
          
          
          /** 更改基本服务参数**/
          CMPPConfig.ServiceCode = pt.getProperty("ServiceCode", "10657");
          System.out.println("服务代码: \t" + CMPPConfig.ServiceCode);
          
          CMPPConfig.BusinessCode = pt.getProperty("BusinessCode", "MLN6919900");
          System.out.println("业务代码: \t" + CMPPConfig.BusinessCode);
          
        }
        catch(Exception ex){
            System.out.println("[CMPP] loadInitCfg error :" +ex) ;
        }
      }
    public CMPPConfig() {
        this.loadInitCfg();
    }
}
